package com.qfedu.yanglao20admin.plancase.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qfedu.yanglao20.common.CommonResult;
import com.qfedu.yanglao20.common.annotation.LogInfo;
import com.qfedu.yanglao20.entity.plancase.AccidentType;
import com.qfedu.yanglao20admin.plancase.param.AccidentTypeParam;
import com.qfedu.yanglao20admin.plancase.service.AccidentTypeService;
import com.qfedu.yanglao20admin.plancase.vo.AccidentTypeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yujie
 * @data 2023/4/21 20:07
 */
@Api(tags = "事故类型")
@RestController
@RequestMapping("/accident")
public class AccidentTypeController {

    @Resource
    private AccidentTypeService accidentTypeService;


    @LogInfo
    @ApiOperation(value = "分页展示事故类型信息", notes = "分页展示事故类型信息")
    @GetMapping("/page")
    public CommonResult<AccidentTypeVO> page(AccidentTypeParam param) {
        Page<AccidentTypeVO> accidentTypePage = accidentTypeService.pageAccidentType(param);
        return CommonResult.success(accidentTypePage);
    }

    @LogInfo
    @ApiOperation(value = "根据id删除事故类型信息", notes = "根据id删除事故类型信息")
    @GetMapping("/delete")
    public CommonResult<AccidentType> deleteAccidentType(@RequestParam @ApiParam("事故类型id") Integer id) {
        accidentTypeService.deleteById(id);
        return CommonResult.success();
    }

    @LogInfo
    @ApiOperation(value = "添加事故类型信息", notes = "添加事故类型信息")
    @PostMapping("/add")
    public CommonResult<AccidentType> addAccidentType(AccidentType accidentType) {
        accidentTypeService.insertAccidentType(accidentType);
        return CommonResult.success();
    }

    @LogInfo
    @ApiOperation(value = "根据id查询事故类型信息", notes = "根据id查询事故类型信息")
    @GetMapping("/query")
    public CommonResult<AccidentType> queryAccidentType(@RequestParam @ApiParam("事故类型id") Integer id) {
        AccidentType accidentType = accidentTypeService.queryAccidentType(id);
        return CommonResult.success(accidentType);
    }

    @LogInfo
    @ApiOperation(value = "修改事故类型信息", notes = "修改事故类型信息")
    @PostMapping("/update")
    public CommonResult<AccidentType> updateAdhibition(AccidentType accidentType) {
        accidentTypeService.updateAccidentType(accidentType);
        return CommonResult.success();
    }

    @LogInfo
    @ApiOperation(value = "查询所有事故类型信息", notes = "查询所有事故类型信息")
    @GetMapping("/all")
    public CommonResult<AccidentType> queryAllAccidentType() {
        List<AccidentType> accidentTypes = accidentTypeService.selectAll();
        return CommonResult.success(accidentTypes);
    }
}
